package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.entity.*;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.WxHomeIndexFloorGoodsVo;
import com.cskaoyan.bean.vo.WxHomeIndexVo;
import com.cskaoyan.controller.wx.service.TopicService;
import com.cskaoyan.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 *  小程序主页Controller
 *
 */
@RestController
@RequestMapping("wx/home")
public class WxHomeController {
    @Autowired
    WxHomeService wxHomeService;

    @Autowired
    GoodsService goodsService;

    // 消费券
    @Autowired
    CouponService couponService;

    @Autowired
    CategoryService categoryService;

    // 广告service,对应Ad实例
    @Autowired
    PromotionService promotionService;

    @Autowired
    BrandService brandService;

    // 专题Service
    @Autowired
    TopicService topicService;


    @RequestMapping("about")
    public BaseRespVo about(){
        WxAbout wxAbout = wxHomeService.selectAbout();
        return BaseRespVo.ok(wxAbout);
    }

    /**
     *  小程序首页
     *
     * @return
     */
    @RequestMapping("index")
    public BaseRespVo index(){
        // 新发布商品列表
        List<Goods> newGoodsList = goodsService.getNewGoodsList();
        // 消费券列表
        List<Coupon> couponList = couponService.getAllEnableCoupons();
        // 一级类目列表
        List<Category> categoryList = categoryService.getAllLevelOneCategorys();
        // 团购列表
        List<GroupOn> grouponList = new ArrayList<>();
        // 横幅，广告列表
        List<Ad> adList = promotionService.getAllEnableAds();
        // 品牌列表
        List<Brand> brandList = brandService.getAllBrand();
        // 热卖商品列表
        List<Goods> hotGoodsList = goodsService.getHotGoodsList();
        // 专题列表
        List<Topic> topicList = topicService.getAllTopics();
        // 一级类目下的推荐商品，限制四个
        List<WxHomeIndexFloorGoodsVo> homeIndexFloorGoodsVos = goodsService.getWxHomeIndexFloorGoods(categoryList);

        WxHomeIndexVo wxHomeIndexVo = new WxHomeIndexVo(newGoodsList,couponList,categoryList,grouponList,
                adList,brandList,hotGoodsList,topicList,homeIndexFloorGoodsVos);
        return BaseRespVo.ok(wxHomeIndexVo);
    }

}
